<?php
/**
 * Copyright © 2013-2017 Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

/** @var \Magento\Customer\Block\Form\Edit $block */
?>
<form class="form form-edit-account" action="<?php echo $block->escapeUrl($block->getUrl('customer/account/editPost')) ?>" method="post" id="form-validate" enctype="multipart/form-data" data-hasrequired="<?php echo $this->helper(\Magento\Framework\EscapeHelper::class)->escapeHtmlAttr(__('* Required Fields')) ?>" autocomplete="off">
    <fieldset class="fieldset info">
        <?php echo $block->getBlockHtml('formkey')?>
        <legend class="legend"><span><?php echo $block->escapeHtml(__('Account Information')) ?></span></legend><br>
        <?php echo $block->getLayout()->createBlock(\Magento\Customer\Block\Widget\Name::class)->setObject($block->getCustomer())->toHtml() ?>
        <div class="field email required">
            <label class="label" for="email"><span><?php echo $block->escapeHtml(__('Email')) ?></span></label>
            <div class="control">
                <input type="email" name="email" id="email" value="<?php echo $block->escapeHtml($block->getCustomer()->getEmail()) ?>" title="<?php /* @escapeNotVerified */ echo __('Email') ?>" class="input-text" data-validate="{required:true, 'validate-email':true}">
            </div>
        </div>
        <?php $_dob = $block->getLayout()->createBlock(\Magento\Customer\Block\Widget\Dob::class) ?>
        <?php $_taxvat = $block->getLayout()->createBlock(\Magento\Customer\Block\Widget\Taxvat::class) ?>
        <?php $_gender = $block->getLayout()->createBlock(\Magento\Customer\Block\Widget\Gender::class) ?>
        <?php if ($_dob->isEnabled()): ?>
            <?php echo $_dob->setDate($block->getCustomer()->getDob())->toHtml() ?>
        <?php endif ?>
        <?php if ($_taxvat->isEnabled()): ?>
            <?php echo $_taxvat->setTaxvat($block->getCustomer()->getTaxvat())->toHtml() ?>
        <?php endif ?>
        <?php if ($_gender->isEnabled()): ?>
            <?php echo $_gender->setGender($block->getCustomer()->getGender())->toHtml() ?>
        <?php endif ?>
        <div class="field choice">
            <input type="checkbox" name="change_password" id="change-password" value="1" title="<?php echo $this->helper(\Magento\Framework\EscapeHelper::class)->escapeHtmlAttr(__('Change Password')) ?>"<?php if ($block->getChangePassword()): ?> checked="checked"<?php endif; ?> class="checkbox" />
            <label class="label" for="change-password"><span><?php echo $block->escapeHtml(__('Change Password')) ?></span></label>
        </div>
    </fieldset>

    <fieldset class="fieldset password">
        <legend class="legend"><span><?php echo $block->escapeHtml(__('Change Password')) ?></span></legend><br>
        <div class="field password current required">
            <label class="label" for="current-password"><span><?php echo $block->escapeHtml(__('Current Password')) ?></span></label>
            <div class="control">
                <input type="password" class="input-text" name="current_password" id="current-password" autocomplete="off">
            </div>
        </div>
        <div class="field new password required">
            <label class="label" for="password"><span><?php echo $block->escapeHtml(__('New Password')) ?></span></label>
            <div class="control">
                <input type="password" class="input-text" name="password" id="password" autocomplete="off">
            </div>
        </div>
        <div class="field confirm password required">
            <label class="label" for="password-confirmation"><span><?php echo $block->escapeHtml(__('Confirm New Password')) ?></span></label>
            <div class="control">
                <input type="password" class="input-text" name="password_confirmation" id="password-confirmation" autocomplete="off">
            </div>
        </div>
    </fieldset>
    <div class="actions-toolbar">
        <div class="primary">
            <button type="submit" class="action save primary" title="<?php echo $this->helper(\Magento\Framework\EscapeHelper::class)->escapeHtmlAttr(__('Save')) ?>"><span><?php echo $block->escapeHtml(__('Save')) ?></span></button>
        </div>
        <div class="secondary">
            <a class="action back" href="<?php echo $block->escapeUrl($block->getBackUrl()) ?>"><span><?php echo $block->escapeHtml(__('Go back')) ?></span></a>
        </div>
    </div>
</form>
<script>
    require([
        "jquery",
        "mage/mage"
    ], function($){
        var dataForm = $('#form-validate');
        var ignore = <?php /* @escapeNotVerified */ echo $_dob->isEnabled() ? '\'input[id$="full"]\'' : 'null'; ?>;
        
        dataForm.mage('validation', {
        <?php if ($_dob->isEnabled()): ?>
            errorPlacement: function(error, element) {
                if (element.prop('id').search('full') !== -1) {
                    var dobElement = $(element).parents('.customer-dob'),
                        errorClass = error.prop('class');
                    error.insertAfter(element.parent());
                    dobElement.find('.validate-custom').addClass(errorClass)
                        .after('<div class="' + errorClass + '"></div>');
                }
                else {
                    error.insertAfter(element);
                }
            },
            ignore: ':hidden:not(' + ignore + ')'
        <?php else: ?>
            ignore: ignore ? ':hidden:not(' + ignore + ')' : ':hidden'
        <?php endif ?>
        });

    });
</script>
<script type="text/x-magento-init">
    {
        "#change-password": {
            "setPassword": {
                "currentPasswordId": "#current-password",
                "passwordId": "#password",
                "confirmationId": "#password-confirmation",
                "passwordContainer": "fieldset.fieldset.password",
                "showOnDefault": <?php /* @escapeNotVerified */ echo $block->getChangePassword() ? 'true' : 'false' ?>
            }
        }
    }
</script>
